/**
 * 
 */
package com.rostami.tutorial.spring.lifeCycle;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author Alireza
 * These 2 interfaces do the exact work of postconstruct and predestroy annotation
 */
public class LifeCycleWithImpBeans implements InitializingBean , DisposableBean {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		ApplicationContext context = new ClassPathXmlApplicationContext("SpringConfig.xml");
		LifeCycleWithImpBeans obj = (LifeCycleWithImpBeans)context.getBean("lifeCycleWithImpBeans");
		obj.greeting();
		((AbstractApplicationContext)context).registerShutdownHook();

	}

	@Override
	public void destroy() throws Exception {
		System.out.println("destroy");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("init");
	}
	
	public void greeting(){
		System.out.println("Greeting from the body");
	}

}
